package com.passengerflowmanagementsystem.statistics.service.impl;

import com.alibaba.fastjson2.JSONObject;
import com.passengerflowmanagementsystem.statistics.domain.vo.*;
import com.passengerflowmanagementsystem.statistics.service.IPassengerService;
import com.passengerflowmanagementsystem.statistics.utils.GetCameraPreviewURL;
import org.springframework.stereotype.Service;


/**
 * 客流Service业务层处理
 *
 * @author sheng
 * @date 2024-11-25
 */
@Service
public class PassengerServiceImpl implements IPassengerService {


    /**
     * 按统计组查询人脸客流统计数据
     * @return
     */
    public String faceFlowStatGroups(FaceFlowStatGroupsVo faceFlowStatGroupsVo){
        String url = "/api/cfas/v1/faceFlow/stat/groups";
        JSONObject jsonBody = new JSONObject();
        jsonBody.put("granularity", faceFlowStatGroupsVo.getGranularity());
        jsonBody.put("startTime", faceFlowStatGroupsVo.getStartTime());
        jsonBody.put("endTime", faceFlowStatGroupsVo.getEndTime());
        jsonBody.put("ids", faceFlowStatGroupsVo.getIds());
        jsonBody.put("ageType", faceFlowStatGroupsVo.getAgeType());
        jsonBody.put("gender", faceFlowStatGroupsVo.getGender());
        String body = jsonBody.toJSONString();
        return GetCameraPreviewURL.GetCameraPreviewURL(url,body);
    }

    /**
     * 查询时间范围内的多个统计组的客流统计数据
     * @return
     */
    public String passengerFlowGroups(PassengerFlowGroupsVo passengerFlowGroupsVo){
        String url = "/api/cfas/v2/passengerFlow/groups";
        JSONObject jsonBody = new JSONObject();
        jsonBody.put("ids", passengerFlowGroupsVo.getIds());
        jsonBody.put("granularity", passengerFlowGroupsVo.getGranularity());
        jsonBody.put("startTime", passengerFlowGroupsVo.getStartTime());
        jsonBody.put("endTime", passengerFlowGroupsVo.getEndTime());
        String body = jsonBody.toJSONString();
        return GetCameraPreviewURL.GetCameraPreviewURL(url,body);
    }

    /**
     * 查询统计组数据
     * @return
     */
    public String countGroupGroupsPage(CountGroupGroupsPageVo countGroupGroupsPageVo){
        String url = "/api/cfas/v2/countGroup/groups/page";
        JSONObject jsonBody = new JSONObject();
        jsonBody.put("regionId", countGroupGroupsPageVo.getRegionId());
        jsonBody.put("isCascade", countGroupGroupsPageVo.getIsCascade());
        jsonBody.put("groupType", countGroupGroupsPageVo.getGroupType());
        jsonBody.put("statType", countGroupGroupsPageVo.getStatType());
        jsonBody.put("pageNo", countGroupGroupsPageVo.getPageNo());
        jsonBody.put("pageSize", countGroupGroupsPageVo.getPageSize());
        String body = jsonBody.toJSONString();
        return GetCameraPreviewURL.GetCameraPreviewURL(url,body);
    }

    /**
     * 查询统计组密度统计数据
     * @return
     */
    public String passengerDensityGroups(PassengerDensityGroupsVo passengerDensityGroupsVo){
        String url = "/api/cfas/v2/passenger/density/groups";
        JSONObject jsonBody = new JSONObject();
        jsonBody.put("startTime", passengerDensityGroupsVo.getStartTime());
        jsonBody.put("endTime", passengerDensityGroupsVo.getEndTime());
        jsonBody.put("countGroupId", passengerDensityGroupsVo.getCountGroupId());
        jsonBody.put("granularity", passengerDensityGroupsVo.getGranularity());
        String body = jsonBody.toJSONString();
        return GetCameraPreviewURL.GetCameraPreviewURL(url,body);
    }

    /**
     * 查询客流排行
     * @param passengerRankingTopVo
     * @return
     */
    public String passengerRankingTop(PassengerRankingTopVo passengerRankingTopVo){
        String url = "/api/cfas/v3/passenger/ranking/top";
        JSONObject jsonBody = new JSONObject();
        jsonBody.put("startTime", passengerRankingTopVo.getStartTime());
        jsonBody.put("endTime", passengerRankingTopVo.getEndTime());
        jsonBody.put("regionId", passengerRankingTopVo.getRegionId());
        jsonBody.put("granularity", passengerRankingTopVo.getGranularity());
        jsonBody.put("order", passengerRankingTopVo.getOrder());
        jsonBody.put("topNumber", passengerRankingTopVo.getTopNumber());
        jsonBody.put("isCascade", passengerRankingTopVo.getIsCascade());
        String body = jsonBody.toJSONString();
        return GetCameraPreviewURL.GetCameraPreviewURL(url,body);
    }



}
